package nobu.nakata.nfcfare;
import java.util.Map;

import nobu.nakata.nfcfare.resource.impl.BusResource;
import nobu.nakata.nfcfare.resource.impl.BussesResource;
import nobu.nakata.nfcfare.resource.impl.SuicaUsageResource;
import nobu.nakata.nfcfare.resource.impl.TrainResource;
import nobu.nakata.nfcfare.resource.impl.TrainsResource;

import org.restlet.Application;
import org.restlet.Restlet;
import org.restlet.routing.Router;
import org.restlet.routing.Variable;

public class NFCFareServlet extends Application {

	@Override
	public Restlet createInboundRoot() {
        // Create a router Restlet that routes each call to a
        // new instance of HelloWorldResource.
        Router router = new Router(getContext());

        // Defines only one route
        router.attach("/trains", TrainsResource.class);
        Map<String, Variable> routeVariables = router.attach("/trains/{trainCode}", TrainResource.class)
        		.getTemplate().getVariables();
        routeVariables.put("trainCode", new Variable(Variable.TYPE_DIGIT));
        
        router.attach("/busses", BussesResource.class);
        routeVariables = router.attach("/busses/{busCode}", BusResource.class)
        		.getTemplate().getVariables();
        routeVariables.put("busCode", new Variable(Variable.TYPE_DIGIT));
        
        routeVariables = router.attach("/nfc/0300/090F/{usageData}", SuicaUsageResource.class)
        		.getTemplate().getVariables();
        routeVariables.put("usageData", new Variable(Variable.TYPE_ALPHA_DIGIT));
        SuicaUsageResource.USAGE_DATA		= "usageData";
        SuicaUsageResource.trainBaseUrl		= "/rest/trains/";
        SuicaUsageResource.busBaseUrl		= "/rest/busses/";

        return router;
	}
	
}
